-
Notifications
You must be signed in to change notification settings - Fork 1k
Enhance enum definition handling and validation #3124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Added a `string enumTypeName` parameter to the `ToEnumDefinition` methods in `ComplexTypeSystem.cs` and `DataTypeDefinitionExtension.cs` to improve enum field name generation, especially when original names are null or empty. Implemented a fallback mechanism to ensure robust naming. In `ComplexTypeBuilder.cs`, added null checks for `typeName` to prevent runtime errors and ensure valid type definitions. Updated logic for defining enum literals to handle empty field names, ensuring unique names are generated based on `typeName` and enum value.
|
Fix for #3123 |
…ilder.cs Co-authored-by: Copilot <[email protected]>
…on.cs Co-authored-by: Copilot <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3124 +/- ##
==========================================
+ Coverage 57.42% 57.46% +0.04%
==========================================
Files 357 357
Lines 69117 69140 +23
Branches 14203 14216 +13
==========================================
+ Hits 39687 39731 +44
+ Misses 25180 25163 -17
+ Partials 4250 4246 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mrsuciu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a little glitch on calling EnumMemberAttribute
Libraries/Opc.Ua.Client.ComplexTypes/TypeBuilder/ComplexTypeBuilder.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances enum definition handling by adding robust validation and fallback mechanisms for enum field name generation. The changes address potential runtime errors when enum names are null or empty by implementing defensive coding practices and ensuring unique field names are generated.
- Added
enumTypeNameparameter toToEnumDefinitionmethods for improved fallback naming - Implemented null/empty validation for type names and enum fields with appropriate error handling
- Enhanced enum literal definition logic to prevent duplicate field names and handle edge cases
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ComplexTypeBuilder.cs | Added null checks for typeName and enhanced enum field validation with duplicate prevention |
| DataTypeDefinitionExtension.cs | Updated ToEnumDefinition methods to accept enumTypeName parameter and handle null/empty field names |
| ComplexTypeSystem.cs | Updated method calls to pass enum type names to ToEnumDefinition methods |
Added a
string enumTypeNameparameter to theToEnumDefinitionmethods inComplexTypeSystem.csandDataTypeDefinitionExtension.csto improve enum field name generation, especially when original names are null or empty. Implemented a fallback mechanism to ensure robust naming.In
ComplexTypeBuilder.cs, added null checks fortypeNameto prevent runtime errors and ensure valid type definitions. Updated logic for defining enum literals to handle empty field names, ensuring unique names are generated based ontypeNameand enum value.Proposed changes
Describe the changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
Related Issues
Types of changes
What types of changes does your code introduce?
Put an
xin the boxes that apply. You can also fill these out after creating the PR.Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...